package com.checx;

import com.checx.loader.MyClassLoader;
import com.checx.reload.Server;
import com.checx.temporal.C;
import sun.net.spi.nameservice.dns.DNSNameService;

import java.lang.reflect.Method;

public class Main {
    public static void symbolicReference() {
        System.out.println(int.class.getName());
        System.out.println(String.class.getName());
        System.out.println(String[].class.getName());
        System.out.println(int[].class.getName());
        System.out.println(int[][].class.getName());
        String a = "aaa";
        System.out.println(a.length());
        Runnable r = () -> {System.out.println("aa");};
        r.run();
    }

    public static void classLoaderTest() {
        System.out.println(String.class.getClassLoader());
        System.out.println(Main.class.getClassLoader());
        System.out.println(Main[].class.getClassLoader());
        System.out.println(int[].class.getClassLoader());
        System.out.println(DNSNameService.class.getClassLoader());
    }

    public static void reloadClass() throws Exception {
        Server server = new Server();
        server.updateService("./classes");
        server.processRequest();
        System.in.read();
        server.updateService("./classes");
        server.processRequest();
    }

    public static void reloadClass1() throws Exception {
        com.checx.reload1.Server server = new com.checx.reload1.Server();
        server.updateService("./classes");
        server.processRequest();
        System.in.read();
        server.updateService("./classes");
        server.processRequest();
    }

    public static void temporalNamespaceConsistency(){
        C c = new C();
        c.g();
    }

    public static void delegatingNamespaceConsistency() throws Exception{
        MyClassLoader myClassLoader = new MyClassLoader("./classes/delegating");
        Class<?> cls = myClassLoader.loadClass("com.checx.delegating.C");
        Object c = cls.newInstance();
        Method f = cls.getMethod("f");
        f.invoke(c);
    }

    public static void main(String[] args) throws Exception {
        delegatingNamespaceConsistency();
    }
}